<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品详细信息</title>
</head>
<body>
<button onclick="get()" >get</button>

<form id="login" >
    <input type="text" name="name" value="pomelo">
    <input type="text" name="password" value="pomelo">
    <input type="text" name="hobby" value="pomelo">
    <input type="text" name="phone" value="pomelo">
    <input type="text" name="email" value="pomelo">
    <button onclick="send()">提交</button>
</form>
<script src="./axios.js"></script>
<script>
    function get() {
        axios.get("http://localhost:8080/list").then(res => {
            // console.log(res.data)
            let resp = res.data
            if (resp.code === 1) { // 业务请求成功
                let arr = resp.data
                console.log(arr)
            }
        }).catch(err => {
            console.log(err)
        })
    }

    document.querySelector("#login").onsubmit =() => {
        // if (validUsername) {
        //     return true
        // }
        return false  // 阻止表单默认提交事件
    }

    function send() {
        // if (validUsername) {
            axios.post("http://localhost:8080/test").then((res) => {
                console.log(res)
                console.log(res.data)
            }).catch(err => {
                console.log(err)
            })
        // } else {
        //     // 提示不能提交
        // }

    }
</script>
</body>
</html>